	clear all
	set more off
	local directory ""
 
	use "`directory'/main_data", clear
	
	***************************************
	*  				TABLE 1 		  	  *
	***************************************

	local varlist "age male numeracy financial_literacy stocks baseline_GARP baseline_risk_aversion less_high_school high_school some_college college_graduate income_less_10k income_btw_10k_20k income_btw_20k_30k income_btw_30k_40k income_btw_40k_50k  income_btw_50k_60k income_btw_60k_75k income_btw_75k_100k income_btw_100k_150k income_more_150k"
	
	forvalues i = 1/4 {

		summ `varlist' if treatment_arm_`i' == 1 & budget_order == 1

	}
			
	foreach var in `varlist' {

		reg `var' treatment_arm_3 if (treatment_arm_1 == 1 | treatment_arm_3 == 1) & budget_order == 1  
		reg `var' treatment_arm_4 if (treatment_arm_1 == 1 | treatment_arm_4 == 1) & budget_order == 1 
		reg `var' treatment_arm_4 if (treatment_arm_2 == 1 | treatment_arm_4 == 1) & budget_order == 1 
		reg `var' treatment_arm_4 if (treatment_arm_3 == 1 | treatment_arm_4 == 1) & budget_order == 1 

	}

	***************************************
	*  				TABLE 2 		  	  *
	***************************************

	foreach var in return lnreturn return_per risk { 
			
		reg post_`var'	treatment_arm_3	if (treatment_arm_1 == 1 | treatment_arm_3 == 1) & rel_price1 ~= 1, cluster(prim_key)
			
	}

	***************************************
	*  				TABLE 3 		  	  *
	***************************************

	foreach var in post_GARP post_GARP_FOSD dominated_portfolio post_FOSD { 
			
		ranksum `var' 				if treatment_arm_1 == 1 | treatment_arm_3 == 1, by(treatment_arm_3)
		reg `var'	treatment_arm_3 if treatment_arm_1 == 1 | treatment_arm_3 == 1, robust
			
	}

	***************************************
	*  				TABLE 4 		  	  *
	***************************************
	
	foreach var in payoff lnpayoff payoff_per post_FOSD {
	
		reg `var' treatment_arm_4 if treatment_arm_3 == 1 | treatment_arm_4 == 1, cluster(prim_key)
	
	}
	
	***************************************
	*  				TABLE 5 		  	  *
	***************************************

	foreach var in payoff lnpayoff payoff_per post_FOSD {

		reg `var' i.treatment_arm_4#c.DM_ability treatment_arm_4 DM_ability  if treatment_arm_3 == 1 | treatment_arm_4 == 1, cluster(prim_key)

	}
	
	***************************************
	*  				TABLE 6 		  	  *
	***************************************

	reg dominated_choice i.treatment_arm_4#c.DM_ability treatment_arm_4 DM_ability if treatment_arm_3 == 1 | treatment_arm_4 == 1, cluster(prim_key)

	reg dominated_investment i.treatment_arm_4#c.DM_ability treatment_arm_4 DM_ability if treatment_arm_3 == 1 | treatment_arm_4 == 1, cluster(prim_key)

	reg dominated_avoidance i.treatment_arm_4#c.DM_ability treatment_arm_4 DM_ability if treatment_arm_3 == 1 | treatment_arm_4 == 1, cluster(prim_key)

	
	***************************************
	*  				FIGURE 2		  	  *
	***************************************
	
	use "`directory'/figure_2", clear


	preserve

		cumul change_sign if highDMA == 0, gen(Low) equal
		cumul change_sign if highDMA == 1, gen(High) equal
			
		label variable Low  "Low DMS"
		label variable High "High DMS"

		twoway 	(line Low   change_sign if highDMA == 0, sort lcolor(red) lwidth(medthin) lpattern(dash)  connect(stairstep)) ///
				(line High  change_sign if highDMA == 1, sort lcolor(black)   lwidth(medthin) lpattern(solid) connect(stairstep)), ///	
				ylabel(, nogrid) graphregion(fcolor(white)) legend(ring(0) position(3) rows(2) region(lwidth(none))) /// 
			xtitle("Median Number of Times Participant Changed from Increasing to Decreasing" "or from Decreasing to Increasing Amount Received if Heads")
					
	restore
	
	preserve

		cumul time_spent if highDMA == 0, gen(Low) equal
		cumul time_spent if highDMA == 1, gen(High) equal
			
		label variable Low  "Low DMS"
		label variable High "High DMS"

		twoway 	(line Low   time_spent if highDMA == 0, sort lcolor(red) lwidth(medthin) lpattern(dash)  connect(stairstep)) ///
				(line High  time_spent if highDMA == 1, sort lcolor(black)   lwidth(medthin) lpattern(solid) connect(stairstep)), ///	
				ylabel(, nogrid) graphregion(fcolor(white)) ///  
				legend(ring(0) position(3) rows(2) region(lwidth(none))) /// 
			xtitle("Median Number of Minutes Participant Spent Choosing Allocation") ///
			
	restore		
	
	***************************************
	*  				TABLE 7 		  	  *
	***************************************
	
	use "`directory'/main_data" if treatment_arm_4 == 1, clear
	
	/***************************************/
	/*   			scalers  			   */
	/***************************************/
	
	bysort price_tails: egen median = median(endowment)
	gen lnphi = ln(endowment/median)
	drop median

	bysort price_tails: egen median = median(outside_option)
	gen lntheta = ln(outside_option/median)
	drop median
	gen x = lnphi - lntheta
	
	/***************************************/
	/*   		 Estimation			       */
	/***************************************/
	
	gen low  = (1 - highDMA) * x   
	gen high = highDMA 		 * x  
		
	gen opt_in = 1 - avoidance
 	egen group = group(price_tails highDMA) 

	clogit opt_in low high, group(group)
	gen baseline = 1/_b[low]
	gen skill   = (1/_b[high]) - (1/_b[low])
	
	summ baseline
	global lambda_low = r(mean)
	summ skill
	global lambda_high = r(mean) + $lambda_low	
	
		/***************************************/
		/*      bootstrapping sample	       */
		/***************************************/
		
		keep if e(sample)
		
		
		keep prim_key budget_order opt_in low high group
		
		gen nonmissing = 1
		
		reshape wide opt_in low high group nonmissing, i(prim_key) j(budget_order)

		
		compress
		
		tempfile bootstrap
		save `bootstrap', replace
		
		/***************************************/
		/*   		 bootstrapping		       */
		/***************************************/

		clear
		set obs 1
		gen obs = 1
		save "`directory'/bootstrap.dta", replace

		global boot_reps = 500
		local seed_kernel = 88782332

		forvalues b = 1(1)$boot_reps {

			display `b'

			qui {
			
				use `bootstrap', clear

				gen boot_sample = `b'

				local new_seed = `seed_kernel' + `b'
				set seed `new_seed'
				bsample 

				gen ID = _n
				reshape long opt_in low high group nonmissing, i(ID) j(budget_order)
				keep if nonmissing == 1
		
				clogit opt_in low high, group(group)
				gen baseline1 = 1/_b[low]
				gen skill1   = (1/_b[high]) - (1/_b[low])

						
				keep in 1
				keep skill1 baseline1 boot_sample

				append using "`directory'/bootstrap.dta"
				save "`directory'/bootstrap.dta", replace
				
			}	

		}
		
		/***************************************/
		/*      	Bootstrapped SEs	       */
		/***************************************/
		
		_pctile baseline1, p(5, 95)	
		return list

		_pctile skill1, p(5, 95)	
		return list
